package com.fh.controller;

import com.fh.bean.*;
import com.fh.bean.pulc.ResultBody;
import com.fh.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author whf
 * @date 2024年03月22日 11:16
 */
@RestController
@RequestMapping("stream")
@Api(tags = "Stream流对获取数据修改")
public class StreamController {

    @Autowired
    private StudentService studentService;

    @ApiOperation(value = "查询成绩01课程大于02课程接口",notes = "查询成绩01课程大于02课程接口")
    @PostMapping("queryCourseGrade")
    @PreAuthorize("hasRole('BOSS')")
    public ResultBody<List<Student>> queryCourseGradeBig(){
        return ResultBody.ok(studentService.queryCourseGrade());
    }




    @ApiOperation(value = "查询成绩01课程小于02课程接口",notes = "查询\"01\"课程比\"02\"课程成绩低的学生的信息及课程分数")
    @PostMapping("queryCourseGradeSmall")
    @PreAuthorize("@customPermissionEvaluator.hasPermission(authentication, null, 'userResourcePermission')")
    public ResultBody<List<Student>> queryCourseGradeSmall(){
        return ResultBody.ok(studentService.queryCourseGradeSmall());
    }

    @ApiOperation(value = "查询平均成绩大于等于60分的同学",notes = "查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩")
    @PostMapping("queryAvgGradeBigSixty")
    public ResultBody<List<StudentAvgGradeBean>> queryAvgGradeBigSixty(){
        return ResultBody.ok(studentService.queryAvgGradeBigSixty());
    }

    @ApiOperation(value = "查询平均成绩小于60分的同学",notes = "查询平均成绩小于60分的同学的学生编号和学生姓名和平均成绩(包括有成绩的和无成绩的)")
    @PostMapping("queryAvgGradeSmallSixty")
    public ResultBody<List<StudentAvgGradeBean>> queryAvgGradeSmallSixty(){
        return ResultBody.ok(studentService.queryAvgGradeSmallSixty());
    }

    @ApiOperation(value = "查询所有同学的学生编号……",notes = "查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩")
    @PostMapping("queryStudentSumGrade")
    public ResultBody<List<StudentGradeCourseBean>> queryStudentSumGrade(){
        return ResultBody.ok(studentService.queryStudentSumGrade());
    }

    @ApiOperation(value = "查询\"李\"姓老师的数量",notes = "查询\"李\"姓老师的数量")
    @PostMapping("queryLiCount")
    public ResultBody<Long> queryLiCount(){
        return ResultBody.ok(studentService.queryLiCount());
    }


    @ApiOperation(value = "询学过\"张三\"老师授课的同学的信息",notes = "询学过\"张三\"老师授课的同学的信息")
    @PostMapping("queryStudyZsStudent")
    public ResultBody<List<Student>> queryStudyZsStudent(){
        return ResultBody.ok(studentService.queryStudyZsStudent());
    }


    @ApiOperation(value = "查询没学过\"张三\"老师授课的同学的信息",notes = "查询没学过\"张三\"老师授课的同学的信息")
    @PostMapping("queryNotStudyZsStudent")
    public ResultBody<List<Student>> queryNotStudyZsStudent(){
        return ResultBody.ok(studentService.queryNotStudyZsStudent());
    }


    @ApiOperation(value = "查询学过编号为\"01\"并且也学过编号为\"02\"的课程的同学的信息",notes = "查询学过编号为\"01\"并且也学过编号为\"02\"的课程的同学的信息")
    @PostMapping("queryStudyZeroOneAndTwo")
    public ResultBody<List<Student>> queryStudyZeroOneAndTwo(){
        return ResultBody.ok(studentService.queryStudyZeroOneAndTwo());
    }


    @ApiOperation(value = "查询学过编号为\"01\"但是没有学过编号为\"02\"的课程的同学的信息",notes = "查询学过编号为\"01\"但是没有学过编号为\"02\"的课程的同学的信息")
    @PostMapping("queryStudyZeroOneAndNotTwo")
    public ResultBody<List<Student>> queryStudyZeroOneAndNotTwo(){
        return ResultBody.ok(studentService.queryStudyZeroOneAndNotTwo());
    }

    @ApiOperation(value = " 查询和\"01\"号的同学学习的课程完全相同的其他同学的信息",notes = " 查询和\"01\"号的同学学习的课程完全相同的其他同学的信息")
    @PostMapping("queryZeroOneDiscipline")
    public ResultBody<List<Student>> queryZeroOneDiscipline(){
        return ResultBody.ok(studentService.queryZeroOneDiscipline());
    }


    @ApiOperation(value = "查询没学过\"张三\"老师讲授的任一门课程的学生姓名",notes = "查询没学过\"张三\"老师讲授的任一门课程的学生姓名")
    @PostMapping("queryNotStudyZs")
    public ResultBody<List<String>> queryNotStudyZs(){
        return ResultBody.ok(studentService.queryNotStudyZs());
    }

    @ApiOperation(value = "查询两门及其以上不及格课程的同学的学号，姓名及其平均成绩",notes = "查询两门及其以上不及格课程的同学的学号，姓名及其平均成绩")
    @PostMapping("queryNotTwoPass")
    public ResultBody<List<StudentAvgGradeBean>> queryNotTwoPass(){
        return ResultBody.ok(studentService.queryNotTwoPass());
    }

    @ApiOperation(value = "检索\"01\"课程分数小于60，按分数降序排列的学生信息",notes = "检索\"01\"课程分数小于60，按分数降序排列的学生信息")
    @PostMapping("queryGradePassSixty")
    public ResultBody<List<GradePass>> queryGradePassSixty(){
        return ResultBody.ok(studentService.queryGradePassSixty());
    }

    @ApiOperation(value = "按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩",notes = "按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩")
    @PostMapping("queryAvgMark")
    public ResultBody<List<GradeCourse>> queryAvgMark(){
        return ResultBody.ok(studentService.queryAvgMark());
    }

    @ApiOperation(value = "A")
    @RequestMapping("A")
    @PreAuthorize("hasRole('USER')")
    public Object A(){
        return "调用成功";
    }
}
